import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:heytea_kit/entity/location_data.dart';
import 'package:heytea_kit/heytea_kit.dart';
import 'package:heytea_kit/utils/map_utils.dart';

class LocationViewer extends StatelessWidget {
  final Widget mapWidget;
  final LocationData locationData;

  const LocationViewer({
    @required this.mapWidget,
    @required this.locationData,
  });

  @override
  Widget build(BuildContext context) {
    return Stack(
      alignment: Alignment.bottomCenter,
      children: [
        mapWidget,
        Container(
          padding: const EdgeInsets.symmetric(horizontal: 12),
          decoration: BoxDecoration(
            color: CupertinoTheme.of(context).barBackgroundColor,
            borderRadius: BorderRadius.circular(8),
          ),
          height: 80,
          margin: const EdgeInsets.symmetric(vertical: 20, horizontal: 15),
          child: Row(
            children: [
              Expanded(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    if (locationData.title != null)
                      Text(
                        locationData.title,
                        style: Theme.of(context).textTheme.bodyText2.copyWith(
                          fontSize: 17,
                        ),
                        maxLines: 1,
                      ),
                    if (locationData.address != null)
                      Text(
                        locationData.address,
                        style: Theme.of(context).textTheme.bodyText1.copyWith(
                          fontSize: 17,
                        ),
                        maxLines: 1,
                      ),
                  ],
                ),
              ),
              CupertinoButton(
                child: Image.asset(
                  'assets/ic_navigation.png',
                  width: 40,
                  height: 40,
                  package: HeyTeaKit.packageName,
                ),
                padding: EdgeInsets.zero,
                minSize: 0,
                onPressed: () => _onNavigationPressed(context),
              ),
            ],
          ),
        ),
      ],
    );
  }

  Future<void> _onNavigationPressed(BuildContext context) {
    return MapUtils.navigateTo(context, locationData.lat, locationData.lng);
  }
}
